package com.example.demo.service;

import com.example.demo.entity.Product;
import com.example.demo.mapper.ProductMapper;
import com.example.demo.model.PageBean;
import com.example.demo.model.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class ProductService {
    private ProductMapper productMapper;

    public Result getPageData(Integer current, Integer pageSize) {
        Page<Product> page = PageHelper.startPage(current, pageSize);
        productMapper.getAll();
        PageBean<Product> pageBean = new PageBean<>();
        pageBean.setData(page.getResult());
        pageBean.setTotal(page.getTotal());
        pageBean.setCurrent(page.getPageNum());

        return Result.buildSuccess(pageBean);
    }

    public Result getgoodById(Integer goodId) {
        return Result.buildSuccess(productMapper.getGoodById(goodId));
    }
}